Skip to content

Support string coercion for array-form type in OpenAPI 3.1 (runtime) - #21

Closed
modosc wants to merge 1 commit into
openapi-3-2/ruby-versionfrom
type-array-coercion
Closed

modosc wants to merge 1 commit into
openapi-3-2/ruby-versionfrom
type-array-coercion

Conversation

@modosc

@modosc modosc commented Sep 29, 2026 •

Copy link
Copy Markdown

problem

committee passes query, path, and form params to openapi_parser as raw Strings and relies on coerce_value to convert them. 3.1 removed nullable, so a nullable param is written as type: [integer, "null"]. array-form type picks a type by matching the value's class, so "5" matches nothing and fails validation. every request that sends a nullable non-string param is rejected.

solution

  • with coerce_value on, a String that matches no type in an array-form type is coerced by trying each listed non-null type in order ("5" against [integer, "null"] becomes 5)
  • returns the first type that validates, otherwise the first type's error
  • exact class matches are unchanged (a String against [integer, string] stays a String)
  • not gated on document version, matching the other 3.1 runtime changes; array-form type is already flagged in 3.0 docs by TypeArrayIn30
  • no new SpecValidator rule, since this only changes runtime behavior for an existing keyword

depends on #14.

@modosc
modosc force-pushed the type-array-coercion branch from ce9a85b to 056fa6c Compare September 29, 2026 00:50
@modosc
modosc changed the base branch from master to openapi-3-2/ruby-version September 29, 2026 00:50
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@modosc
modosc force-pushed the type-array-coercion branch from 056fa6c to 23a5433 Compare September 29, 2026 01:01
@modosc modosc changed the title Coerce String values into array-form type (3.1) Support string coercion for array-form type in OpenAPI 3.1 (runtime) Sep 29, 2026
@modosc

modosc commented Oct 14, 2026

Copy link
Copy Markdown
Author

merged upstream as ota42y#212

@modosc modosc closed this Oct 14, 2026
@modosc
modosc deleted the type-array-coercion branch October 14, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant